package com.example.softwareconfigurationcoursedesign;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/editUser")
public class EditUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取要修改的会员的ID
        int userIdToEdit = Integer.parseInt(request.getParameter("userId"));
        // 获取用户输入的值
        String name = request.getParameter("userName");
        String phoneNumber = request.getParameter("PhoneNumber");
        String password = request.getParameter("Password");
        // 创建User对象
        User userToEdit = new User(userIdToEdit, name, phoneNumber, password);
        // 创建AdminServlet对象
        AdminServlet adminServlet = new AdminServlet();
        // 调用编辑会员信息的方法
        adminServlet.editUserInDatabase(userToEdit);
        System.out.println("修改会员");
        // 重定向到会员列表页面或其他页面
        response.sendRedirect("editUser.jsp");
    }
}